package main

import (
	"bufio"
	"fmt"
	"net"
	"os"
	"strings"
)

func clientTest() {
	conn, err := net.Dial("tcp", "localhost:50000")
	if err != nil{
		fmt.Println("Error dailing", err.Error())
		return
	}

	inputReader := bufio.NewReader(os.Stdin)
	fmt.Println("First, What is your name?")
	clientName, _ := inputReader.ReadString('\n')
	trimmedClient := strings.Trim(clientName, "\r\n")
	for {
		fmt.Println("What to send to the server? Type Q to quit.")
		input, _ := inputReader.ReadString('\n')
		trimmedInput := strings.Trim(input, "\r\n")
		if trimmedInput == "Q"{
			return
		}
		_, err = conn.Write([]byte(trimmedClient + " says: " + trimmedInput))
	}
}

func checkConnection(conn net.Conn, err error) {
	if err != nil{
		fmt.Printf("error %v connectiong!", err)
		os.Exit(1)
	}
	fmt.Printf("Connection is made with %v\n", conn)
}

func clientTest1() {
	conn, err := net.Dial("tcp", "192.168.255.146:80")
	checkConnection(conn, err)
	conn, err = net.Dial("udp", "192.168.255.146:80")
	checkConnection(conn, err)
	conn, err = net.Dial("tcp", "[2620:0:2d0:200::10]:80")
	checkConnection(conn, err)
}

func main() {
	//clientTest()
	clientTest1()

}
